/**
 * 判断是否字符串
 * @returns {boolean}
 */
export const isString = (value: String) => typeof value === 'string';

export function delSuffix(str = ''): string {
  return str.replace(/\.drc|\.obj|\.vtu|\.vtp/g, '');
}
/**
 * 获取文件名
 * @param {String} str
 * @returns {string}
 */
export const basename = (str: String) => {
  if (!str) return '';
  let idx = str.lastIndexOf('/');
  idx = idx > -1 ? idx : str.lastIndexOf('\\');
  if (idx < 0) {
    return str;
  }
  return str.substring(idx + 1);
};
/**
 * 空函数
 */
export const noop = () => {};

/**
 * 数字转科学计数法
 * @param num
 * @param fractionDigits 小数点后保留的位数
 * @return string 将数字按科学计数法格式返回
 */
export const toExponential = (num:number, fractionDigits:number) => {
  if (Number(num) === 0) return '0';
  return Number(num).toExponential(fractionDigits);
};
/**
 * A wrapper function for pxm.createRepresentationInAllViews that
 * correctly manages which representation is bound to 2D manipulators.
 */
export function createRepresentationInAllViews(pxm:any, source:any) {
  const views2D = pxm.getViews().filter((v:any) => v.isA('vtkView2DProxy'));
  // reach in to get sliceRepresentation, since it's not default exposed
  const origReps = views2D.map((v:any) => v.getReferenceByName('sliceRepresentation'));

  pxm.createRepresentationInAllViews(source);

  // do not focus labelmaps
  if (source.getProxyName() === 'LabelMap') {
    views2D.forEach((view:any, i:any) => view.bindRepresentationToManipulator(origReps[i]));
  }
}

/**
 * 判断是否函数
 * @returns {boolean}
 */
export function isFunction(value:any) {
  return Object.prototype.toString.call(value) === '[object Function]';
}
